package de.mroedig.appindiesonne.menu;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import de.mroedig.appindiesonne.R;

public class ZoneWaehlen extends Activity {

	private int hauttyp;
	private int zone;
	private TextView zonenBeschreibung;

	private Button weiterButton;

	private SeekBar zonenBar;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.zonewaehlen);
		SharedPreferences mPrefs = this.getSharedPreferences(
				"appInDieSonnePrefs", MODE_PRIVATE);
		Editor editor = mPrefs.edit();
		this.hauttyp = mPrefs.getInt("hauttyp", 1);

		editor.commit();

		this.zonenBeschreibung = (TextView) this
				.findViewById(R.id.zonenBeschreibung);

		this.zonenBar = (SeekBar) this.findViewById(R.id.zonenBar);
		this.weiterButton = (Button) this.findViewById(R.id.zoneweiterbutton);

		this.zonenBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				this.seekBarListenerStandardMethode();
			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				this.seekBarListenerStandardMethode();
			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				this.seekBarListenerStandardMethode();
			}

			private void seekBarListenerStandardMethode() {

				ZoneWaehlen.this.zone = ZoneWaehlen.this.zonenBar.getProgress();
				ZoneWaehlen.this.setzeZonenBeschreibung(ZoneWaehlen.this.zone);
			}
		});

		this.weiterButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				SharedPreferences mPrefs = ZoneWaehlen.this
						.getSharedPreferences("appInDieSonnePrefs",
								MODE_PRIVATE);
				Editor editor = mPrefs.edit();

				editor.putInt("zone", ZoneWaehlen.this.zone);
				editor.commit();

				Intent intent = new Intent(ZoneWaehlen.this, ZeitWaehlen.class);

				ZoneWaehlen.this.startActivity(intent);

			}
		});

		this.holePrefs();
	}

	private void holePrefs() {
		SharedPreferences mPrefs = this.getSharedPreferences(
				"appInDieSonnePrefs", MODE_PRIVATE);
		this.zonenBar.setProgress(mPrefs.getInt("zone", 0));

	}

	protected void setzeZonenBeschreibung(int progress) {

		switch (progress) {
		case 0:
			this.zonenBeschreibung.setText(R.string.zone_1);
			break;
		case 1:

			this.zonenBeschreibung.setText(R.string.zone_2);
			break;
		case 2:

			this.zonenBeschreibung.setText(R.string.zone_3);
			break;
		case 3:

			this.zonenBeschreibung.setText(R.string.zone_4);
			break;
		}
	}
}
